#!/bin/bash

# 仓颉0.60.5版本API修复脚本
# 批量修复append和put方法调用

echo "🔧 开始修复仓颉0.60.5版本API问题..."

# 修复ArrayList.append() -> ArrayList.add()
echo "修复ArrayList.append()方法..."
find src -name "*.cj" -exec sed -i '' 's/\.append(/\.add(/g' {} \;

# 修复HashMap.put() -> HashMap.add()
echo "修复HashMap.put()方法..."
find src -name "*.cj" -exec sed -i '' 's/\.put(/\.add(/g' {} \;

# 修复BlockingQueue相关API
echo "修复BlockingQueue API..."
find src -name "*.cj" -exec sed -i '' 's/\.enqueue(/\.add(/g' {} \;
find src -name "*.cj" -exec sed -i '' 's/\.dequeue(/\.remove(/g' {} \;

# 修复std.math中的min/max函数
echo "修复std.math导入..."
find src -name "*.cj" -exec sed -i '' 's/std\.math\.{sqrt, pow, min, max}/std.math.{sqrt, pow}/g' {} \;
find src -name "*.cj" -exec sed -i '' 's/std\.math\.{min, max}/std.math/g' {} \;

echo "✅ API修复完成！"

# 检查修复结果
echo "🔍 检查修复结果..."
echo "剩余的append调用:"
grep -r "\.append(" src/ --include="*.cj" | wc -l

echo "剩余的put调用:"
grep -r "\.put(" src/ --include="*.cj" | wc -l

echo "剩余的enqueue调用:"
grep -r "\.enqueue(" src/ --include="*.cj" | wc -l

echo "剩余的dequeue调用:"
grep -r "\.dequeue(" src/ --include="*.cj" | wc -l

echo "🎯 修复脚本执行完成！"
